<template>
  <div id="contianer">
    <div class="t_tab">
      <span
        class="tab_item"
        :class="{ tab_item_active: item.value === activeTab }"
        v-for="(item, index) in tabArray"
        :key="index"
        @click="tabChange(item)"
      >
        {{ item.label }}
      </span>
    </div>
    <el-row style="padding-top: 10px">
      <el-button
        type="primary"
        v-if="activeTab === '1'"
        size="small"
        icon="el-icon-upload"
        @click="handleUpload"
        >上传文件</el-button
      >
      <el-button type="primary" @click="batchSubmit()" size="small" v-if="activeTab !== '4'">{{ batchTitle }}</el-button>
      <el-button type="primary" @click="handleExport()" size="small" v-if="activeTab == '1' && isAdmin">导出文件清单</el-button>
      <el-button-group class="pull-right">
        <el-form
          :inline="true"
          ref="searchForm"
          :model="searchForm"
          @keyup.enter.native="refreshList()"
          @submit.native.prevent
        >
          <el-form-item>
            <el-select
              v-model="searchForm.profession"
              placeholder="请选择所属专业"
              clearable
            >
              <el-option
                v-for="(item, index) in majorTypeList"
                :key="index"
                :label="item.name"
                :value="item.id"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-select
              v-model="searchForm.fileType"
              placeholder="请选择文件类型"
              clearable
            >
              <el-option
                v-for="(item, index) in fileTypeList"
                :key="index"
                :label="item.name"
                :value="item.id"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item prop="time">
            <el-date-picker
              v-model="time"
              type="daterange"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              value-format="yyyy-MM-dd HH:mm:ss"
              @change="changeTime"
              :default-time="['00:00:00', '23:59:59']">
            </el-date-picker>
          </el-form-item>
          <el-form-item prop="uploadUser" v-if="activeTab === '4'">
            <el-select
              size="small"
              style="width: 100%"
              v-model="searchForm.uploadUser"
              clearable
              filterable
              default-first-option
              placeholder="上传人员"
              v-el-select-lazyloading="lazyloading"
              remote
              :remote-method="remoteMethod"
              @focus="searchFocus"
            >
              <el-option
                v-for="item in userList"
                :key="item.id"
                :value="item.id"
                :label="item.userName"
              ></el-option>
            </el-select>
            <!-- <el-input
              size="small"
              v-model.trim="searchForm.uploadUser"
              placeholder="上传人员"
              clearable
            ></el-input> -->
          </el-form-item>
          <el-form-item prop="fileName">
            <el-input
              size="small"
              v-model.trim="searchForm.fileName"
              placeholder="文件名称"
              clearable
            ></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="refreshList()" size="small"
              >查询</el-button
            >
            <el-button @click="resetSearch()" size="small">重置</el-button>
          </el-form-item>
        </el-form>
      </el-button-group>
    </el-row>
    <el-table
      :data="dataList"
      v-loading="loading"
      border
      size="medium"
      class="table"
      style="width: 100%"
      :max-height="tableClientHeight"
      ref="table"
     @selection-change="handleSelectionChange"
    >
      <el-table-column
        type="selection"
        :selectable="selectableStatus"
        width="55">
      </el-table-column>
      <el-table-column fixed="left" label="序号" align="center" width="60px">
        <template slot-scope="scope">
          <span>{{ scope.$index + (pageNo - 1) * pageSize + 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column
        key="1"
        fixed="left"
        :prop="activeTab === '4' ? 'knowledgeName' : 'fileName'"
        width="200px"
        label="文件名称"
        :show-overflow-tooltip="true"
      >
        <template slot-scope="scope">
          <span class="scopeTitle" @click="detailFn(scope.row)" v-if="activeTab !== '4'">
            {{ scope.row.fileName }}
          </span>
          <span class="scopeTitle" v-else>
            {{ scope.row.knowledgeName }}
          </span>
        </template>
      </el-table-column>
      <el-table-column
        key="2"
        prop="fileCode"
        width="150px"
        show-overflow-tooltip
        label="文件编号"
        v-if="activeTab === '1'"
      >
      </el-table-column>
      <el-table-column key="3" :prop="this.activeTab === '4' ? 'knowledgeVersion' : 'fileVersion'" label="文件版次">
      </el-table-column>
      <el-table-column
        key="4"
        prop="versionStatus"
        label="版次状态"
        v-if="activeTab === '1'"
      >
        <template slot-scope="scope">
          <span>{{ scope.row.versionStatus === 0 ? "废止" : "现行" }}</span>
        </template>
      </el-table-column>

      <el-table-column
        key="5"
        prop="author"
        label="作者姓名"
        v-if="activeTab === '1'"
      >
      </el-table-column>
      <el-table-column key="6" prop="uploadUser" label="上传人员">
      </el-table-column>
      <el-table-column key="7" prop="uploadTime" label="上传日期">
      </el-table-column>

      <el-table-column
        key="8"
        prop="fileTypeName"
        show-overflow-tooltip
        label="文件类型"
      >
      </el-table-column>
      <el-table-column key="9" prop="professionName" label="所属专业">
      </el-table-column>
      <el-table-column key="10" prop="fileFormat" label="文件格式">
      </el-table-column>

      <el-table-column key="11" prop="statusName" label="文件状态" v-if="activeTab !== '3' && activeTab !== '4'">
        <template slot-scope="scope">
          <el-popover
            v-if="scope.row.statusName == '驳回'"
            placement="top-start"
            width="200"
            trigger="hover"
            :content="scope.row.reason"
          >
            <span
              slot="reference"
              style="cursor: pointer"
              :style="scope.row.statusName == '驳回' ? 'color:red' : ''"
              >{{ scope.row.statusName }}</span
            >
          </el-popover>

          <span
            v-else
            style="cursor: pointer"
            :style="scope.row.statusName == '驳回' ? 'color:red' : ''"
            >{{ scope.row.statusName }}</span
          >
        </template>
      </el-table-column>
      <el-table-column
        key="12"
        prop="approvalTypeName"
        label="审核类型"
        v-if="activeTab !== '1' && activeTab !== '4'"
      >
      </el-table-column>
      <el-table-column
        v-if="activeTab === '1'"
        key="13"
        prop="analyseStatusName"
        label="解析状态"
      >
        <template slot-scope="scope">
          <el-popover
            v-if="scope.row.analyseStatus == 1"
            placement="top-start"
            width="200"
            trigger="hover"
            :content="scope.row.analyseDescription"
          >
            <span
              slot="reference"
              style="cursor: pointer"
              :style="scope.row.analyseStatusName == '失败' ? 'color:red' : ''"
              >{{ scope.row.analyseStatusName }}</span
            >
          </el-popover>
          <span
            v-else
            slot="reference"
            style="cursor: pointer"
            :style="scope.row.analyseStatusName == '失败' ? 'color:red' : ''"
            >{{ scope.row.analyseStatusName }}</span
          >
        </template>
      </el-table-column>
      <el-table-column key="14" prop="approvalTypeName" label="申请类型" v-if="activeTab === '4'"></el-table-column>
      <el-table-column key="15" prop="approvalUserName" label="审批人员" v-if="activeTab === '4'"></el-table-column>
      <el-table-column key="16" prop="approvalResultName" label="审批结果" v-if="activeTab === '4'"></el-table-column>
      <el-table-column key="17" prop="approvalTime" label="审批时间" width="160px" v-if="activeTab === '4'"></el-table-column>
      <el-table-column
        fixed="right"
        header-align="center"
        width="260px"
        label="操作"
        v-if="activeTab !== '4'"
      >
        <template slot-scope="scope">
          <!-- <div v-if="activeTab === '1' && ( scope.row.folderType == 1 || scope.row.analyseStatus == 0)"> -->
          <div v-if="activeTab === '1' ">
            <el-button type="text" size="small" @click="detailFn(scope.row)"
              >查看
            </el-button>
            <el-button
              type="text"
              size="small"
              @click="editFn(scope.row)"
              v-if="scope.row.permissionVo.update"
              >更新
            </el-button>
            <el-button
              style="color: red"
              type="text"
              size="small"
              @click="del(scope.row)"
              v-if="scope.row.permissionVo.delete"
            >
              删除
            </el-button>
            <el-button
              type="text"
              size="small"
              @click="withdraw(scope.row)"
              v-if="scope.row.permissionVo.withdraw"
              >撤回
            </el-button>
            <el-button
              type="text"
              size="small"
              @click="handleFile(scope.row)"
              v-if="scope.row.permissionVo.submit"
              >提交
            </el-button>
            <el-button
              type="text"
              size="small"
              @click="handleOpen(scope.row)"
              v-if="scope.row.fileType == 35"
              >{{ scope.row.expansionStatus == 1 ? '关闭' : '开启' }}
            </el-button>
            <!-- <el-button type="text" size="small" @click="editVideo(scope.row)"
              >编辑
            </el-button> -->
          </div>

          <div v-if="activeTab === '2'">
            <el-button type="text" size="small" @click="detailFn(scope.row)"
              >查看
            </el-button>
            <el-button
              type="text"
              size="small"
              @click="rejectReview(scope.row.id)"
            >
              驳回
            </el-button>
            <el-button type="text" size="small" @click="passReview(scope.row)"
              >通过
            </el-button>
          </div>

          <div v-if="activeTab === '3'">
            <el-button type="text" size="small" @click="detailFn(scope.row)"
              >查看
            </el-button>
            <el-button
              type="text"
              size="small"
              @click="rejectApprove(scope.row.id)"
            >
              驳回
            </el-button>
            <el-button type="text" size="small" @click="passApprove(scope.row)"
              >通过
            </el-button>
          </div>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageNo"
      :page-size="pageSize"
      :total="total"
      style="text-align: right; margin-top: 10px"
      layout="total, prev, pager, next, jumper"
      background
    >
    </el-pagination>
    <!-- 添加或修改用户配置对话框 -->
    <el-dialog
      title="文件上传"
      :visible.sync="dialogVisible"
      :close-on-click-modal="false"
      width="600px"
      append-to-body
      :before-close="handleClose"
    >
      <el-form
        ref="uploadForm"
        :model="uploadForm"
        :rules="rules"
        label-width="80px"
      >
        <el-form-item label="专业类型" prop="majorType">
          <el-select
            v-model="uploadForm.majorType"
            placeholder="请选择专业类型"
            style="width: 100%"
            clearable
          >
            <el-option
              v-for="(item, index) in majorTypeList"
              :key="index"
              :label="item.name"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="文件类型" prop="fileType">
          <el-select
            v-model="uploadForm.fileType"
            placeholder="请选择文件类型"
            style="width: 100%"
            clearable
          >
            <el-option
              v-for="(item, index) in fileTypeList"
              :key="index"
              :label="item.name"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">下一步</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 驳回 -->
    <el-dialog
      title="驳回"
      :visible.sync="elementsVisible"
      width="30%"
      center
      :close-on-click-modal="false"
    >
      <el-form
        :model="ruleForm"
        :rules="rules"
        ref="ruleForm"
        label-width="100px"
        class="demo-ruleForm"
      >
        <el-form-item label="驳回原因" prop="reason">
          <el-input
            maxlength="500"
            :disabled="ruleForm.disabled"
            show-word-limit
            v-model.trim="ruleForm.reason"
            type="textarea"
            :rows="3"
          ></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" v-if="!ruleForm.disabled" class="dialog-footer">
        <el-button type="primary" @click="elementsConfirm">确 定</el-button>
        <el-button @click="elementsVisibleClose">取 消</el-button>
      </span>
    </el-dialog>
    <!-- 更新 -->
    <el-dialog
      title="更新"
      :visible.sync="updateVisible"
      width="30%"
      center
      :close-on-click-modal="false"
    >
      <el-form
        :model="updateForm"
        :rules="updaterules"
        ref="updateForm"
        label-width="100px"
        class="demo-ruleForm"
      >
        <el-form-item label="专业类型" prop="profession">
          <el-select
            v-model="updateForm.profession"
            placeholder="请选择专业类型"
            style="width: 100%"
            disabled
            clearable
          >
            <el-option
              v-for="(item, index) in majorTypeList"
              :key="index"
              :label="item.name"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="文件类型" prop="fileType">
          <el-select
            disabled
            v-model="updateForm.fileType"
            placeholder="请选择文件类型"
            style="width: 100%"
            clearable
          >
            <el-option
              v-for="(item, index) in fileTypeList"
              :key="index"
              :label="item.name"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="上传文件" prop="fileId">
          <el-upload
            :action="uploadImgUrl"
            class="upload-demo"
            :show-file-list="false"
            :accept="acceptType"
            :on-success="uploadSuccess"
            :before-upload="beforeUpload"
            drag
            :headers="headers"
            show-file-list
          >
            <i class="el-icon-upload"></i>
            <div class="el-upload__text">
              将文件拖到此处，或<em>点击上传</em>
            </div>
            <div class="el-upload__tip" slot="tip">
              只能上传{{ acceptType }}类型的文件
            </div>
          </el-upload>
        </el-form-item>

        <el-form-item label="文件名称" prop="fileName">
          <el-input
            maxlength="100"
            v-model="updateForm.fileName"
            placeholder="请输入文件名称"
          ></el-input>
        </el-form-item>
        <el-form-item label="作者姓名" prop="author">
          <el-input
            maxlength="100"
            v-model="updateForm.author"
            placeholder="请输入作者姓名"
          ></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="updateConfirm">确 定</el-button>
        <el-button @click="updateVisibleClose">取 消</el-button>
      </span>
    </el-dialog>

    <!-- 预览 -->
    <el-dialog
      custom-class="previewIframe"
      :visible.sync="previewVisible"
      fullscreen
      center
      :close-on-click-modal="false"
    >
      <iframe
        v-loading="previewLoading"
        id="iframe"
        src=""
        frameborder="0"
        width="100%"
        height="100%"
      ></iframe>
    </el-dialog>
    <!-- 预览视频 -->
    <el-dialog
      custom-class="previewIframe"
      :visible.sync="videoVideoVisible"
      :close-on-click-modal="false"
      fullscreen
      center
    >
      <div class="video_model">
        <div id="video"></div>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import PreviewUpload from "@/components/accessory/PreviewUploadFile";

export default {
  dicts: ["sys_user_sex"],
  components: {
    PreviewUpload,
  },
  data() {
    return {
      elementsVisible: false,
      updateVisible: false,
      previewVisible: false,
      previewLoading: true,
      videoVideoVisible: false,
      previewUrl: "",
      batchIds:[],
      batchTitle:"批量提交",
      tabArray: [
        {
          label: "原文件管理",
          value: "1",
          number: 0,
          fmtNumber: 0,
        },
        {
          label: "审核任务管理",
          value: "2",
          number: 0,
          fmtNumber: 0,
        },
        {
          label: "批准任务管理",
          value: "3",
          number: 0,
          fmtNumber: 0,
        },
        {
          label: "审批记录",
          value: "4",
          number: 0,
          fmtNumber: 0,
        },
      ],
      time: [],
      activeTab: "1",
      searchForm: {
        fileName: "",
        fileType: "",
        profession: "",
        uploadUser: "",
        startTime: "",
        endTime: "",
      },
      ruleForm: {
        reason: "",
        disabled: false,
      },
      updateForm: {
        author: "",
        fileId: "",
        fileName: "",
        fileType: "",
        id: "",
        profession: "",
      },
      dataList: [],
      pageNo: 1,
      pageSize: 10,
      total: 0,
      orderBy: "",
      dataListSelections: [],
      loading: false,
      dialogVisible: false,
      uploadForm: {
        majorType: "",
        fileType: "",
      },
      userForm:{
        name:''
      },
      elementsVisibleId: "", // 驳回任务id
      uploadFileId: "",
      uploadImgUrl:this.$config.VUE_APP_BASE_API + "/file/upload", // 上传的图片服务器地址
      headers: {
        token: localStorage.getItem("token"),
      },
      fileTypeList: [],
      majorTypeList: [],
      userList: [],
      acceptType: "",
      fileSize: "",
      rules: {
        majorType: [
          { required: true, message: "请选择专业类型", trigger: "change" },
        ],
        fileType: [
          { required: true, message: "请选择文件类型", trigger: "change" },
        ],
      },
      updaterules: {
        profession: [
          { required: true, message: "请选择专业类型", trigger: "change" },
        ],
        fileType: [
          { required: true, message: "请选择文件类型", trigger: "change" },
        ],
        fileName: [
          { required: true, message: "请输入文件名称", trigger: "blur" },
        ],
        author: [
          { required: true, message: "请输入作者名称", trigger: "blur" },
        ],
      },
    };
  },
  computed: {
    isAdmin() {
      return this.$store.state.user.isAdmin;
    },
    tableClientHeight() {
      let tableClientHeight =
        document.documentElement.clientHeight || document.body.clientHeight;
      tableClientHeight = tableClientHeight - 389;
      return tableClientHeight;
    },
  },
  activated() {
    this.refreshList();
  },
  mounted() {
    console.log("看看config配置",this.$config)
    this.fileTypeListFn();
    this.majorTypeListFn();
    if (this.$route.query.fileType) {
      console.log(
        this.$route.query.fileType,
        typeof this.$route.query.fileType
      );
      this.searchForm.fileType = Number(this.$route.query.fileType);
    }
    this.refreshList();
  },
  methods: {
    fileTypeListFn() {
      this.$http({
        url: "/dict/file/list",
        method: "GET",
        params: {},
      }).then(({ data }) => {
        console.log(data.data.data);
        this.fileTypeList = data.data.data;
      });
    },
    majorTypeListFn() {
      this.$http({
        url: "/dict/major/list",
        method: "GET",
        params: {},
      }).then(({ data }) => {
        console.log(data.data.data);
        this.majorTypeList = data.data.data;
      });
    },
    searchFocus(){
      this.userForm.name = ""
      this.searchForm.pageNumber = 1
      this.getUserList();
    },
    remoteMethod(e){
      console.log('eeee',e)
      this.userForm.name = e
      this.searchForm.pageNumber = 1
      this.userList = []
      this.getUserList();
    },
    //下拉框懒加载
    lazyloading() {
      console.log('55555')
      if( this.searchForm.pageNumber > this.searchForm.totalPage){
        return
      }
      this.searchForm.pageNumber++
      this.getUserList()
    },
    getUserList() {
      this.$http({
        url: "/knowledgeLabel/userList",
        method: "get",
        params: {
          pageSize: this.searchForm.pageSize,
          pageNumber: this.searchForm.pageNumber,
          name: this.userForm.name
        },
      }).then(({ data }) => {
        if (data.code == 200) {
          if(data.data.pageNumber == 1){
            this.userList = data.data.data;
          }else{
            this.userList = this.userList.concat(data.data.data == [] ? [] : data.data.data);
          }
          this.searchForm.pageSize = data.data.pageSize;
          this.searchForm.pageNumber = data.data.pageNumber;
          this.searchForm.totalPage = data.data.totalPage;
        }
      });
    },
    // 表格多选操作
    handleSelectionChange(e){
      this.batchIds = e.map(item => item.id).toString();
      console.log(e,this.batchIds,'ffff')
    },
    // 切换tab
    tabChange(d) {
      this.pageNo = 1;
      this.total = 0;
      this.activeTab = d.value;
      console.log('activeTab',this.activeTab)
      if(this.activeTab == '1'){
        this.batchTitle = "批量提交"
      }else if(this.activeTab == '2'){
        this.batchTitle = "批量审核"
      }else if(this.activeTab == '3'){
        this.batchTitle = "批量批准"
      }else{
        this.batchTitle = "审批记录"
      }
      this.refreshList();
    },
    cancel() {
      this.dialogVisible = false;
      this.uploadForm = {
        majorType: "",
        fileType: "",
      }
      this.$nextTick(()=>{
        this.$refs.uploadForm.clearValidate();
      })
    },
    submitForm() {
      console.log(this.uploadForm, "---");
      this.$refs.uploadForm.validate((valid) => {
        if (valid) {
          const path = [35].includes(this.uploadForm.fileType)
            ? "/knowledgeManage/originalFile/UploadVideoForm"
            : "/knowledgeManage/originalFile/UploadForm";
          this.$router.push({
            path,
            query: {
              fileType: this.uploadForm.fileType,
              profession: this.uploadForm.majorType,
            },
          });
        }
      });
    },
    selectableStatus(row, rowIndex){
      if((row.folderType == 0 && (this.activeTab == '1' && row.permissionVo && row.permissionVo.submit)) || this.activeTab == '2' || this.activeTab == '3'){
        return true
      }else{
        return false
      }
    },
    // 弹窗关闭
    handleClose(){
      this.dialogVisible = false; 
      this.uploadForm = {
        majorType: "",
        fileType: "",
      }
      this.$nextTick(()=>{
        this.$refs.uploadForm.clearValidate(); 
      })
    },
    // 驳回原因
    rejectFn(item) {
      if (item.status == 2) {
        // 查看驳回原因
        this.ruleForm.reason = item.reason;
        this.ruleForm.disabled = true;
        this.elementsVisible = true;
      }
    },
    // 解析失败原因
    analysisFn(item) {},
    // 获取数据列表
    refreshList() {
      this.dataList = [];
      this.loading = true;
      let url = "";
      switch (this.activeTab) {
        case "1":
          url = "/knowledgeFile/list";
          break;
        case "2":
          url = "/knowledgeFile/review/list";
          break;
        case "3":
          url = "/knowledgeFile/approve/list";
          break;
        default:
          url = "/knowledgeApprovalRecord/list";
          break;
      }
      if (this.activeTab !== "4") {
        this.$http({
          url: url,
          method: this.activeTab == "4" ? "post" : "get",
          params: {
            ...this.searchForm,
            pageSize: this.pageSize,
            pageNumber: this.pageNo,
          },
        }).then(({ data }) => {
          this.dataList = data.data.data;
          this.total = data.data.totalSize;
          this.loading = false;
        });
      } else {
        this.$http({
            url: url,
            method: "post",
            data: {
              ...this.searchForm,
              pageSize: this.pageSize,
              pageNumber: this.pageNo,
            },
          }).then(({ data }) => {
          this.dataList = data.data.data;
          this.total = data.data.totalSize;
          this.loading = false;
        });
      }

    },
    elementsConfirm() {
      this.elementsVisible = false;
      this.ruleForm.disabled = false;

      const url =
        this.activeTab === "2"
          ? "/knowledgeFile/review/turnDown"
          : "/knowledgeFile/approve/turnDown";
      this.$http({
        url,
        method: "post",
        data: {
          id: this.elementsVisibleId,
          reason: this.ruleForm.reason,
        },
      }).then(({ data }) => {
        if (data.code == 200) {
          this.$message.success("驳回成功");
          this.elementsVisible = false;
          this.ruleForm.reason = "";
          this.refreshList();
        } else {
          this.$message.error("驳回失败");
        }
      });
    },
    elementsVisibleClose() {
      this.elementsVisible = false;
      this.ruleForm.disabled = false;
      this.ruleForm.reason = "";
    },
    uploadSuccess(res, file, fileList) {
      console.log(fileList);
      if (fileList.length > 1) {
        fileList = fileList.splice(0, 1);
        // return
      }

      this.$message.success("上传成功");
      this.updateForm.fileId = res.data.id;
    },
    // 更新确定
    updateConfirm() {
      this.$refs["updateForm"].validate((valid) => {
        if (valid) {
          this.$http({
            url: "/knowledgeFile/file/update",
            method: "post",
            data: this.updateForm,
          })
            .then(({ data }) => {
              if (data.code == 200) {
                this.$message.success("更新成功");
                this.updateVisible = false;
                this.refreshList();
              } else {
                this.$message.error("更新失败");
              }
            })
            .catch((err) => {
              this.$message.error("更新失败");
            });
        }
      });
    },
    // 进入详情或者预览
    detailFn(row) {
      let that = this;
      console.log(row, "55555");
      if ([35].includes(row.fileType) && this.activeTab === "1") {
        this.$router.push({
          path: "/knowledgeManage/originalFile/UpdateVideoForm",
          query: { id: row.id, isVideoGroup: true, isPreview: true },
        });
        return;
      }
      if (row.analyseStatus != 0) {
        this.$message.warning("文件正在解析中，不可预览");
        return;
      }
      this.$http({
        url: "/knowledgeData/preview",
        method: "get",
        params: {
          id: row.id,
        },
      }).then(({ data }) => {
        if (row.fileType == 38 || (row.fileType == 35 && ["mp4", "mov","avi", "wmv"].includes(row.fileFormat))) {
          this.videoVideoVisible = true;
          setTimeout(() => {
            new this.$Player({
              id: "video", // 元素id
              lang: "zh", // 设置中文
              volume: 0, // 默认静音
              autoplay: false, // 自动播放
              screenShot: false, // 开启截图功能
              height: 200,
              // 视频地址
              url: this.$config.VUE_APP_BASE_API_QA + data.data.downloadUrl,
              // 封面图
              // poster:'',
              fluid: true, // 填满屏幕 （流式布局）
              playbackRate: [0.5, 0.75, 1, 1.5, 2], // 传入倍速可选数组
            });
          }, 300);
          return;
        }
        this.previewVisible = true;
        setTimeout(() => {
          var iframe = document.querySelector("#iframe");
          console.log(iframe, this.$config.VUE_APP_BASE_API, "iframe");
          this.populateIframe(
            iframe,
            [["token", +localStorage.getItem("token")]],
            this.$config.VUE_APP_BASE_API_QA + data.data.downloadUrl
          );
        }, 0);
      });
    },
    populateIframe(iframe, headers, url) {
      var xhr = new XMLHttpRequest();
      xhr.open("GET", url);
      xhr.responseType = "blob";
      headers.forEach((header) => {
        xhr.setRequestHeader(header[0], header[1]);
      });
      // xhr.setRequestHeader("X-Amz-Server-Side-Encryption-Customer-Key-MD5", "m7AXuOLSaEQc1369IHCZGw==")
      // xhr.setRequestHeader("X-Amz-Server-Side-Encryption-Customer-Algorithm", "AES256")
      // xhr.setRequestHeader("X-Amz-Server-Side-Encryption-Customer-Key", "5svVq6aMjTLMBTD0yaIT9u735QnpHteabx6nFZUXvac=")
      xhr.onreadystatechange = () => {
        if (xhr.readyState === xhr.DONE) {
          if (xhr.status === 200) {
            console.log(URL.createObjectURL(xhr.response), "ffff");
            this.previewUrl = URL.createObjectURL(xhr.response);
            console.log("预览地址", URL.createObjectURL(xhr.response));
            iframe.src =
              "./static/pdfjs/web/viewer.html?file=" +
              URL.createObjectURL(xhr.response);
          }
        }
      };
      xhr.send();
    },
    updateVisibleClose() {
      this.updateVisible = false;
    },
    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val;
      this.pageNo = 1;
      this.refreshList();
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageNo = val;
      this.refreshList();
    },
    // 更新
    editFn(row) {
      console.log(row);

      // 需要判断当前状态 已入库需要有弹框提示
      if (row.status == 5) {
        this.$confirm(`原文件已入库，如需更新，需对 原文件进行升版`, "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
            this.updateFileFn(row);
          })
          .catch(() => {});
      } else {
        this.updateFileFn(row);
      }
    },

    // editVideo(row) {
    //   this.$router.push({
    //     path: "/knowledgeManage/originalFile/UploadVideoForm",
    //     query: {
    //       fileType: row.fileType,
    //       profession: row.profession,
    //       id: row.id,
    //       from: "editVideo",
    //     },
    //   });
    // },
    // 批量提交
    batchSubmit(){
      let url = ''
      if(this.activeTab == '1'){
        url = '/knowledgeFile/file/batchSubmit'
      }else if(this.activeTab == '2'){
        url = '/knowledgeFile/review/batchPass'
      }else{
        url = '/knowledgeFile/approve/batchPass'
      }
      if(this.batchIds == ""){
        this.$message.warning("请选择提交内容")
        return
      }

      this.$http({
        url,
        method:'post',
        data:{
          ids:this.batchIds
        }
      }).then(({ data}) => {
        this.$message.success(`${this.batchTitle}成功`)
        this.refreshList();
      })
    },
    updateFileFn(row) {
      // return
      if (row.folderType === 0) {
        //文件
        this.updateForm = JSON.parse(JSON.stringify(row));
        console.log(this.updateForm, row);
        // 这里处理文件的大小及类型显示
        this.fileSize = 2 * 1024 * 1024 * 1024; // 1 GB
        if ([31, 32].includes(row.fileType)) {
          this.acceptType = ".doc,.docx,.pdf";
        }
        if ([33, 34].includes(row.fileType)) {
          this.acceptType = ".xls,.xlsx,.doc,.docx,.pdf";
        }
        if (row.fileType == 38) {
          this.acceptType = ".avi,.mp4,.wmv,.mov";
          this.fileSize = 3 * 1024 * 1024 * 1024;
        }
        this.$forceUpdate();

        this.updateVisible = true;
      } else {
        //1视频
        // this.$router.push({
        //   path: "/knowledgeManage/originalFile/UpdateVideoForm",
        //   query: { id: row.id },
        // });
        this.$router.push({
          path: "/knowledgeManage/originalFile/UploadVideoForm",
          query: {
            fileType: row.fileType,
            profession: row.profession,
            id: row.id,
            from: "editVideo",
            title: row.fileName
          },
        });
      }
    },

    // 查看
    view(id) {},
    // 删除
    del(row) {
      this.$confirm(
        `确定删除${row ? "[" + row.fileName + "]" : "选中项"}吗?`,
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      ).then(() => {
        this.$http({
          url: "/knowledgeFile/file/delete",
          method: "post",
          data: { id: row.id },
        }).then(({ data }) => {
          if (data.code == 200) {
            this.$message.success(data.msg);
          } else {
            this.$message.warning(data.msg);
          }
          this.refreshList();
        });
      });
    },
    handleFile(row) {
      this.$confirm(
        `确定提交${row ? "[" + row.fileName + "]" : "选中项"}吗?`,
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      ).then(() => {
        this.$http({
          url: "/knowledgeFile/file/submit",
          method: "post",
          data: { id: row.id },
        }).then(({ data }) => {
          this.$message.success(data.msg);
          this.refreshList();
        });
      });
    },
    withdraw(row) {
      this.$confirm(
        `确定撤回${row ? "[" + row.fileName + "]" : "选中项"}吗?`,
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      ).then(() => {
        this.$http({
          url: "/knowledgeFile/file/withdraw",
          method: "post",
          data: { id: row.id },
        }).then(({ data }) => {
          this.$message.success(data.msg);
          this.refreshList();
        });
      });
    },
    handleOpen(row) {
      this.$confirm(
        `确定${ row.expansionStatus == 1 ? '关闭' : '开启' }${ row ? "[" + row.fileName + "]" : "选中项" }吗?`,
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      ).then(() => {
        this.$http({
          url: "/knowledgeFile/file/switchVideoFolder",
          method: "post",
          data: {
            id: row.id,
            expansionStatus: row.expansionStatus == 1 ? 0 : 1,
          },
        }).then(({ data }) => {
          this.$message.success(data.msg);
          this.refreshList();
        });
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.$utils.download({
        url: "/knowledgeFile/exportKnowledgeFileList",
        method: "get",
        params: {
          ...this.searchForm,
        },
        defaultFileName: `文件清单_${new Date().getTime()}.xlsx`,
      });
    },
    // 审核任务驳回
    rejectReview(id) {
      this.elementsVisible = true;
      this.elementsVisibleId = id;
      this.ruleForm.disabled = false;
      this.ruleForm.reason = "";
    },
    passReview(row) {
      this.$confirm(
        `确定通过${row ? "[" + row.fileName + "]" : "选中项"}吗?`,
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      ).then(() => {
        this.$http({
          url: "/knowledgeFile/review/pass",
          method: "post",
          data: { id: row.id },
        }).then(({ data }) => {
          this.$message.success(data.msg);
          this.refreshList();
        });
      });
    },
    // 批准驳回
    rejectApprove(id) {
      this.elementsVisible = true;
      this.elementsVisibleId = id;
    },
    passApprove(row) {
      this.$confirm(
        `确定通过${row ? "[" + row.fileName + "]" : "选中项"}吗?`,
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      ).then(() => {
        this.$http({
          url: "/knowledgeFile/approve/pass",
          method: "post",
          data: { id: row.id },
        }).then(({ data }) => {
          this.$message.success(data.msg);
          this.refreshList();
        });
      });
    },
    resetSearch() {
      this.searchForm.fileName = "";
      this.searchForm.fileType = "";
      this.searchForm.profession = "";
      this.searchForm.startTime = "";
      this.searchForm.endTime = "";
      this.searchForm.uploadUser = "";
      this.time = [];
      this.refreshList();
    },
    handleUpload() {
      this.dialogVisible = true;
    },
    // 上传文件过滤
    beforeUpload(file) {
      const fileTypes = this.acceptType.split(",");
      const fileName = file.name.lastIndexOf(".");
      const fileNameLen = file.name.length;
      const fileTypeName = file.name.substring(fileName, fileNameLen);
      const fileIndex = fileTypes.indexOf(fileTypeName);
      const isLt2M = file.size < this.fileSize;
      if (fileIndex == -1) {
        this.$message({
          showClose: true,
          message: "您选择的文件格式不在系统支持的范围内，请重新选择！",
          type: "warning",
        });
        return false;
      }
      if (!isLt2M) {
        this.$message.error(
          `系统仅允许单个附件大小在${
            this.fileSize / 1024 / 1024 / 1024
          }G以内的文件进行上传，本次上传有文件超出限制，请重新选择！`
        );
        return false;
      } else if (file.size === 0) {
        this.$message.warning("上传文件不能为空！");
      }
      return isLt2M;
    },
    changeTime(val) {
      this.searchForm.startTime = val ? val[0] : "";
      this.searchForm.endTime = val ? val[1] : "";
    },
  },
};
</script>

<style scoped lang="scss">
#contianer {
  width: 98%;
  min-height: 96%;
  background: white;
  border-radius: 10px;
  padding: 20px 20px 50px;
  margin: 1%;
  float: left;

  .t_tab {
    margin-bottom: 20px;
    padding-top: 10px;

    .tab_item {
      display: inline-block;
      font-size: 20px;
      padding: 0 20px 8px;
      margin-right: 20px;
      border-bottom: 2px solid #fff;
      cursor: pointer;
      transition: all 0.3s ease 0s;

      &:hover {
        opacity: 0.65;
      }
    }

    .tab_item_active {
      font-weight: bold;
      color: #0081f5;
      border-bottom: 2px solid #0081f5;
    }
  }
}

.video_model {
  // width: 260px;
  // height: 190px;
  width: 100%;
  // height: 85vh !important;
  // background: red;
  // border: 1px solid #e6e6e6;
  border-radius: 5px;
  margin-bottom: 20px;

  #video {
    flex: auto;
    height: 85vh !important;
  }

  .video_info {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 10px;
    line-height: 22px;

    h3 {
      flex: 1;
      padding: 0;
      margin: 0;
      font-weight: 550;
      font-size: 18x;
    }

    .author,
    .blurb {
      font-size: 14px;
    }
  }
}

.table .el-button--small {
  padding: 0 10px;
}

.el-table th.el-table__cell > .cell {
  //white-space: nowrap;
}
::v-deep .previewIframe {
  .el-dialog__body {
    height: calc(100% - 30px);
  }
}
</style>
